<?php

/* Get options set on the options page */

$options = get_option( 'wpwt_plugin_options' );

/* Construct and register the options page */

add_action( 'admin_init', 'wpwt_plugin_options_init' );
add_action( 'admin_menu', 'wpwt_plugin_options_add_page' );


function wpwt_plugin_options_init(){
	register_setting( 'wpwt_options', 'wpwt_plugin_options' );
}

function wpwt_plugin_options_add_page() {
	add_menu_page( __( 'WPWT Options' , 'wordpress-word-trainer'), __( 'WPWT Options' , 'wordpress-word-trainer'), 'manage_options', 'wpwt_plugin_options_page', 'wpwt_plugin_options_do_page', null, 5 );
}

function wpwt_plugin_options_do_page() {
	global $select_options;

	if ( ! isset( $_REQUEST['settings-updated'] ) )
		$_REQUEST['settings-updated'] = false;

	?>
	<div class="wrap">
	
		<?php screen_icon(); echo "<h2>" .__( 'WPWT Options' , 'wordpress-word-trainer') . "</h2>"?>

		<?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
		<div class="updated fade"><p><strong><?php _e( "Settings saved!" , 'wordpress-word-trainer'); ?></strong></p></div>
		<?php endif?>

		<form method="post" action="options.php">
			<?php settings_fields( 'wpwt_options' ); ?>
			<?php $options = get_option( 'wpwt_plugin_options' ); ?>

			<table class="form-table">

				<tr valign="top"><th scope="row"><?php _e( "Autologin" , 'wordpress-word-trainer'); ?></th>
					<td>
            <input type="text" name="wpwt_plugin_options[autologin_user]" value="<?php echo esc_attr( $options['autologin_user'] ); ?>" />
						<label class="description" for="wpwt_plugin_options[autologin_user]"><?php _e( "Enter a username to autologin to." , 'wordpress-word-trainer'); ?></label>
					</td>
				</tr>
				
				<tr valign="top"><th scope="row"></th>
					<td>
            <input type="password" name="wpwt_plugin_options[autologin_pass]" value="<?php echo esc_attr( $options['autologin_pass'] ); ?>" />
						<label class="description" for="wpwt_plugin_options[autologin_pass]"><?php _e( "Enter a password with which to authenticate." , 'wordpress-word-trainer'); ?></label>
					</td>
				</tr>
			
      </table>
      
      <p><?php _e( "It is recommended not to set autologin to an account which has privileges to change the website." , 'wordpress-word-trainer'); ?></p>
      
			<p class="submit">
				<input type="submit" class="button-primary" value="Opslaan" />
			</p>
			
		</form>
		
	</div>
	<?php
}

// adapted from http://planetozh.com/blog/2009/05/handling-plugins-options-in-wordpress-28-with-register_setting/